<template>
    <div class="error-page">
      <div class="error-content">
        <div class="error-code">
          <span>{{ errorCode }}</span>
        </div>
        <h2 class="error-title">{{ errorTitle }}</h2>
        <p class="error-message">{{ errorMessage }}</p>
        <button class="back-btn" @click="goBack">返回上一页</button>
        <router-link to="/" class="home-link">返回首页</router-link>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref, computed, onMounted } from 'vue';
  import { useRoute, useRouter } from 'vue-router';
  
  const route = useRoute();
  const router = useRouter();
  
  // 从路由参数获取错误信息
  const errorCode = computed(() => route.query.code || '404');
  const errorTitle = computed(() => {
    if (errorCode.value === '404') return '页面不存在';
    if (errorCode.value === '500') return '服务器错误';
    return '未知错误';
  });
  const errorMessage = computed(() => {
    if (errorCode.value === '404') return '你访问的页面不存在或已被删除。';
    if (errorCode.value === '500') return '服务器暂时无法处理请求，请稍后再试。';
    return '发生了未知错误，请重试或联系客服。';
  });
  
  // 返回上一页
  const goBack = () => {
    router.back();
  };
  </script>
  
  <style scoped>
  .error-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
    padding: 40px;
    text-align: center;
  }
  
  .error-content {
    max-width: 600px;
  }
  
  .error-code {
    font-size: 120px;
    font-weight: bold;
    color: #007bff;
    margin-bottom: 20px;
  }
  
  .error-title {
    font-size: 36px;
    font-weight: bold;
    color: #333;
    margin-bottom: 15px;
  }
  
  .error-message {
    font-size: 18px;
    color: #666;
    margin-bottom: 40px;
  }
  
  .back-btn {
    background-color: #007bff;
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    margin-right: 15px;
  }
  
  .back-btn:hover {
    background-color: #0056b3;
  }
  
  .home-link {
    color: #007bff;
    font-size: 16px;
    text-decoration: none;
    display: inline-block;
    padding: 12px 24px;
    border: 1px solid #007bff;
    border-radius: 4px;
    transition: all 0.2s ease;
  }
  
  .home-link:hover {
    background-color: #007bff;
    color: #fff;
  }
  </style>